﻿using System;
using System.Linq;
using Model.Interfaces;

namespace Model.ModelClasses
{
    public class Person : AbstractModel, IPerson
    {
        public string FamilyName
        { get; set; }

        public string Name
        { get; set; }

        public string FatherName
        { get; set; }

        public string FullName
        {
            get { return FamilyName + " " + Name + " " + FatherName; }
            set
            {
                var str = from s in value.Split(' ') where !string.IsNullOrWhiteSpace(s) select s;
                if (str.Count() > 3)
                {
                    var message = str.Aggregate("Ошибка распознания ФИО!: ", (current, s) => current + ("[" + s + "] "));
                    message += "\nlength: " + str.Count();
                    throw new Exception(message);
                }
                try { FamilyName = str.ElementAt(0); }
                catch { }
                try { Name = str.ElementAt(1); }
                catch { }
                try { FatherName = str.ElementAt(2); }
                catch { }
            }
        }

        public DateTime? Birthday
        { get; set; }

        public IAddress Address
        { get; set; }

        public IContactInformation ContactInformation
        { get; set; }
    }
}